import { createApp } from 'vue'
// import './style.css'
import App from './App.vue'
import router from './router'
import './assets/less/index.less'

// 如果您正在使用CDN引入，请删除下面一行。
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import store from './store/index'

// import './api/mock.ts'
import api from './api/api'

const app = createApp(App);

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
};

app.config.globalProperties.$api = api;

store.commit('addMenu', router);

function checkRouter(path) {
    let hasCheck = router.getRoutes().filter(route => route.path == path).length;
    if (hasCheck) {
        return true;
    } else {
        return false;
    }
}

// 路由守卫
router.beforeEach((to, from, next) => {
    store.commit('getToken');
    const token = store.state.token;
    console.log(to.name);
    // if (to.name == 'register') {
    //     next({ name: 'register' })
    // } else if (!token && to.name !== 'login') {
    //     next({ name: 'login' })
    // } else if (!checkRouter(to.path)) {
    //     next({ name: 'home' })
    // } else {
    //     next();
    // }

    next();
})

app.use(router).use(store);
app.mount('#app');
